<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            padding: 0;
            margin: 0;
            box-sizing: border-box;
        }
        
        .table {
            width: 600px;
            margin: 100px auto 0;
        }
        
        li {
            list-style: none;
            text-align: center;
        }
        
        .up {
            overflow: hidden;
        }
        
        .up li {
            float: left;
            /* 注意这里没有给宽度，不能使用flex，需要通过js来计算 */
            height: 50px;
            line-height: 44px;
            border-top: 3px solid #000;
            border-bottom: 3px solid #000;
            border-left: 1px solid #000;
            border-right: 1px solid #000;
        }
        
        .up li:first-child {
            border-left: 3px solid #000;
        }
        
        .up li:last-child {
            border-right: 3px solid #000;
        }
        
        .down li {
            /* 注意这里全部隐藏起来了，通过js来显示 */
            display: none;
            width: 100%;
            height: 300px;
            line-height: 294px;
            border: 3px solid #000;
            border-top: 0;
            color: white;
        }
    </style>
</head>

<body>
    <div class="table">
        <ul class="up">
            <li style="width: 20%; background: red; border-bottom: 3px solid red; color: white;">red</li>
            <li style="width: 20%; background: orange;">orange</li>
            <li style="width: 20%; background: yellow;">yellow</li>
            <li style="width: 20%; background: green;">green</li>
            <li style="width: 20%; background: blue;">blue</li>
        </ul>
        <ul class="down">
            <li style="background: red; display: block;">我是red颜色</li>
            <li style="background: orange;">我是orange颜色</li>
            <li style="background: yellow;">我是yellow颜色</li>
            <li style="background: green;">我是green颜色</li>
            <li style="background: blue;">我是blue颜色</li>
        </ul>
    </div>
    <script>
        var arr = ['red', 'orange', 'yellow', 'green', 'blue', 'skyblue'];
        var up = document.querySelector('.up');
        var down = document.querySelector('.down');
        for (var i = 0; i < arr.length; i++) {
            var li = document.createElement('li');
            li.setAttribute('data-index', i)
            li.innerHTML = arr[i];
            li.style.background = arr[i];
            li.style.width = `${100/arr.length}%`;
            up.appendChild(li)
            var lis = document.createElement('li');
            lis.innerHTML = `{arr[i]}`;
            lis.style.background = arr[i];
            down.appendChild(lis)
        }
        var uplis = up.children;
        var downlis = down.children;
        for (var i = 0; i < uplis.length; i++) {
            uplis[i].onclick = function() {
                var index = this.getAttribute('data-index')
                for (var j = 0; j < uplis.length; j++) {
                    uplis[j].style.color = 'black';
                    uplis[j].style.borderBottom = '2px solid black'
                    downlis[j].style.display = 'none'
                }
                this.style.color = 'white';
                this.style.borderBottom = '2px solid transparent'
                downlis[index].style.display = 'block';
            }

        }
        downlis[0].style.display = 'block';
        uplis[0].style.borderBottom = '2px solid transparent';
    </script>

</body>

</html>